﻿using System;
using System.Runtime.InteropServices;

namespace StockLib.Data
{
    // 除权数据包 20 字节
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct XdrFilePack
    {
        public Int32 m_time;            // UCT
        public Single m_fGive;          // 每股送
        public Single m_fPei;           // 每股配
        public Single m_fPeiPrice;      // 配股价,仅当 m_fPei!=0.0f 时有效
        public Single m_fProfit;        // 每股红利

        public static XdrFilePack FromInternal(XdrData xdrData)
        {
            XdrFilePack xdrPack = new XdrFilePack();
            xdrPack.m_time = xdrData.Time;
            xdrPack.m_fGive = xdrData.Give;
            xdrPack.m_fPei = xdrData.Pei;
            xdrPack.m_fPeiPrice = xdrData.PeiPrice;
            xdrPack.m_fProfit = xdrData.Profit;

            return xdrPack;
        }

        public static XdrData ToInternal(ref XdrFilePack xdrPack)
        {
            XdrData xdrData = new XdrData();
            xdrData.Time = xdrPack.m_time;
            xdrData.Give = xdrPack.m_fGive;
            xdrData.Pei = xdrPack.m_fPei;
            xdrData.PeiPrice = xdrPack.m_fPeiPrice;
            xdrData.Profit = xdrPack.m_fProfit;

            return xdrData;
        }
    };
}
